import Vue from "vue";
import VueRouter from "vue-router";
import login from "../views/login.vue";
// axios
import axios from "axios";
import VueAxios from "vue-axios"
// bootstrap
import "bootstrap/dist/css/bootstrap.min.css";
import "bootstrap/dist/js/bootstrap.min.js";

Vue.use(VueAxios,axios);
Vue.use(VueRouter);

const routes = [
  // 黄杰
  {path: "/",component: login,redirect: "/login"},
  {path: "/login",component: login,meta: { isokpath:true }},
  //雷梓豪
  {path: "/home",component: () =>import(/* webpackChunkName: "about" */ "../views/home.vue"),
    children:[
      {path:"gzt",component:()=>import("@/views/worktable.vue")},//工作台
      {path:"/",redirect: "gzt"},
      {path:"member",component:()=>import("@/views/hj/Member.vue")},//会员
      {path:"user",component:()=>import("@/views/hj/user.vue")},//用户
      { path: 'rr', component:()=>import("@/views/lzh/reservation .vue") },//
      { path: 'exercise', component:()=>import("@/views/lzh/exercise.vue") },//运动
      { path: 'food', component:()=>import("@/views/lzh/food.vue") },//食品
      { path: 'package', component:()=>import("@/views/lzh/package.vue") },//套餐
      { path: 'jbk', component:()=>import("@/views/lzh/jbk.vue") },//疾病
      { path: 'jcx', component:()=>import("@/views/lzh/jcx.vue") },//检查项,
      { path: 'booking', component:()=>import("@/views/lzh/booking.vue") },//预约列表,
      { path: 'bookingset', component:()=>import("@/views/lzh/bookingset.vue") },//预约设置,
      { path: 'project', component:()=>import("@/views/lzh/project.vue") },//检查项目组管理,
      {path:"role",component:()=>import("@/views/hj/role.vue")},//角色
      {path:"menu",component:()=>import("@/views/hj/menu.vue")},//菜单
      {path:"tjsc",component:()=>import("@/views/hxj/tjsc.vue")},//体检上传
      {path:"physique",component:()=>import("@/views/hj/Physique.vue")},//体质检测
      {path:"psychology",component:()=>import("@/views/hj/Psychology.vue")},//心理检测
      {path:"groupClassification",component:()=>import("@/views/hj/GroupClassification.vue")},//人群分类,
      {path:"statistics",component:()=>import("@/views/lzh/statistics.vue")},//工作量统计
      {path:"mould",component:()=>import("@/views/hj/Mould.vue")},//模板管理
      {path:"interposeScheme",component:()=>import("@/views/hj/InterposeScheme.vue")},//干预方案
      {path:"interposeFollowupVisit",component:()=>import("@/views/hj/InterposeFollowupVisit.vue")},//回访日记
      {path:"worktable",component:()=>import("@/views/worktable.vue")},//工作台
      {path:"/",redirect: "worktable"},
      {path:"memberstatistics",component:()=>import("@/views/lzh/memberstatistics.vue")}
    ]
  },
  // 何新杰

];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach((to, from, next) => {
  //用户如果已经登陆，放行
  //用户需要登录，应该放行
  // 路由中有 isokpath属性，表示因该放行的路由(url)
 /* console.log(to)*/
  if(to.matched.some(val=>val.meta.isokpath==true )){
         next()
  }else{
        if(sessionStorage.getItem("userName")){
             next();
        }else{
        next({path:"/login"});
     }
  }
})

export default router;
